﻿ namespace InternetBankService.Model
 {
     using System.Security.Cryptography;

     public class CryptoModel
     {
         public byte[] ServerPublicKey { get; set; }
         public byte[] ServerSecretKey { get; set; }
         public byte[] InitializationVector { get; set; }

         public Aes Aes { get; set; }
         public ECDiffieHellmanCng Algorithm { get; set; }

         public string IPAdress { get; set; }

         public CryptoModel()
         {
             Aes = new AesCryptoServiceProvider();
             Algorithm = new ECDiffieHellmanCng
                 {
                     KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash,
                     HashAlgorithm = CngAlgorithm.Sha256
                 };

             ServerPublicKey = Algorithm.PublicKey.ToByteArray();
         }


         public void GenerateSecreteKey(byte[] clientPublicKey)
         {
             ServerSecretKey = Algorithm.DeriveKeyMaterial(CngKey.Import(clientPublicKey, CngKeyBlobFormat.EccPublicBlob));
         }
     }
 }